
// <copyright file="NotifyCollection.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The notify collection.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Windows.Forms
{
    using System;
    using System.Collections.ObjectModel;

    /// <summary>
    /// The notify collection.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public class NotifyCollection<T> : Collection<T>
    {
        #region Public Events

        /// <summary>
        /// The collection changed.
        /// </summary>
        public event EventHandler CollectionChanged;

        #endregion Public Events

        #region Methods

        /// <summary>
        /// The clear items.
        /// </summary>
        protected override void ClearItems()
        {
            base.ClearItems();
            this.OnCollectionChanged(EventArgs.Empty);
        }

        /// <summary>
        /// The Insert item.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        protected override void InsertItem(int index, T item)
        {
            base.InsertItem(index, item);
            this.OnCollectionChanged(EventArgs.Empty);
        }

        /// <summary>
        /// The on collection changed.
        /// </summary>
        /// <param name="e">
        /// The e.
        /// </param>
        protected virtual void OnCollectionChanged(EventArgs e)
        {
            if (this.CollectionChanged != null)
            {
                this.CollectionChanged(this, e);
            }
        }

        /// <summary>
        /// The remove item.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        protected override void RemoveItem(int index)
        {
            base.RemoveItem(index);
            this.OnCollectionChanged(EventArgs.Empty);
        }

        /// <summary>
        /// The set item.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        protected override void SetItem(int index, T item)
        {
            base.SetItem(index, item);
            this.OnCollectionChanged(EventArgs.Empty);
        }

        #endregion Methods
    }
}
